package com.weather.controller;

import com.weather.common.core.domain.R;
import com.weather.pojo.entity.Qweather;
import com.weather.pojo.entity.Weather;
import com.weather.service.QweatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/qweather")
@Api(tags = "天气信息")
public class QweatherController {
    @Resource
    private QweatherService qweatherService;

    @GetMapping("/getQweatherList")
    @ApiOperation("获取地理信息")
    public R<List<Qweather>> getQweatherList(String city) throws IOException {
        return R.ok(qweatherService.getQweatherList(city));
    }

    @GetMapping("/getLocationId")
    @ApiOperation("获取城市ID")
    public R<String> getLocationId(String city) throws IOException {
        return R.ok(qweatherService.getLocationId(city));
    }

    @GetMapping("/getWeatherByLocationId/{locationId}")
    @ApiOperation("获取天气信息")
    public R<Weather> getWeatherByLocationId(@PathVariable("locationId") String locationId) throws IOException {
        return R.ok(qweatherService.getWeatherByLocationId(locationId));
    }

}
